<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of frontApi
 *
 * @author Administrator
 */
class frontAction extends BaseAction{
    /**
     * 生成腾讯短连接
     */
    function actionTencentUrl() {
        set_time_limit(60);
        $uhash    = $this->postVar('uhash');
        $re = array('code' => 'error','msg'=>'参数为空');
        if(!empty($uhash)) {
            $rs = DAO_Finder::daoOne(DB_URL, array('uhash' => $uhash));
            if($rs) {
                $url    = $rs->getUrl();
                $re   = trim(file_get_contents('http://u22.cc/servlet/tencent_url/url/'.  base64_encode($url)));
                if(strlen($re) == 6) {
                    $rs->setTencentUrl($re);
                    $rs->save();
                    $re = array('code' => 'ok','msg' => $re);
                }else{
                    $re['msg'] = '错误原因：'.$re.'\n请联系我们.';
                }
            }
        }else{
            //$re   = '';
        }
        echo json_encode($re);
    }

    /**
     * 生成新浪短连接
     */
    function actionSinaUrl() {
        set_time_limit(60);
        $uhash    = $this->postVar('uhash');
        $re = array('code' => 'error','msg'=>'参数为空');
        if(!empty($uhash)) {
            $rs = DAO_Finder::daoOne(DB_URL, array('uhash' => $uhash));
            if($rs) {
                $url    = $rs->getUrl();
                $re   = trim(file_get_contents('http://u22.cc/servlet/sina_url/url/'.  base64_encode($url)));
                if(strlen($re) == 6) {
                    $rs->setSinaUrl($re);
                    $rs->save();
                    $re = array('code' => 'ok','msg' => $re);
                }else{
                    $re['msg'] = '错误原因：'.$re.'\n请联系我们.';
                }
            }
        }else{
            //$re   = '';
        }
        echo json_encode($re);
    }
}
?>
